﻿using System.Threading;
using System.Web;

namespace Cookbook.Services.Core.Common
{
    public static class PrincipleHelper
    {
        /// <summary>
        /// Make sure the thread's current principal is set. If it is not set and there is a current HttpContext,
        /// the thread's current principal is set to the current HttpContext user.
        /// </summary>
        public static void EnsureCurrentPrincipal()
        {
            if ((Thread.CurrentPrincipal.Identity.Name.Length == 0) && (HttpContext.Current != null))
            {
                Thread.CurrentPrincipal = HttpContext.Current.User;
            }
        }
    }
}
